<template>
  <div class="user-details">
    <h1>用户详情</h1>

    <div class="card">
      <div class="card-header">
        <h2>用户信息</h2>
      </div>
      <div class="card-body">
        <p><strong>用户ID：</strong>{{ $route.params.id }}</p>
        <p><strong>姓名：</strong>{{ user.name }}</p>
        <p><strong>邮箱：</strong>{{ user.email }}</p>
        <p><strong>年龄：</strong>{{ user.age }}</p>
      </div>
      <div class="card-footer">
        <button class="btn back" @click="$router.back()">返回列表</button>
      </div>
    </div>
  </div>
</template>

<script>
import axios from 'axios';

export default {
  name: 'UserDetails',
  data() {
    return {
      user: {}
    };
  },
  async mounted() {
    const id = this.$route.params.id;
    const res = await axios.get(`http://localhost:8081/api/users/${id}`);
    this.user = res.data;
  }
};
</script>

<style scoped>
.user-details {
  max-width: 600px;
  margin: 2rem auto;
  padding: 1rem;
  font-family: Arial, sans-serif;
}

.card {
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  transition: all 0.3s ease;
}

.card-header {
  background-color: #0d6efd;
  color: white;
  padding: 1rem;
}

.card-header h2 {
  margin: 0;
  font-size: 1.5rem;
}

.card-body {
  padding: 1.5rem;
  line-height: 1.6;
  color: #333;
}

.card-body p {
  margin: 0.5rem 0;
}

.card-footer {
  padding: 1rem;
  text-align: right;
  background-color: #f9f9f9;
  border-top: 1px solid #eee;
}

.btn {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: bold;
  transition: background-color 0.3s ease;
}

.back {
  background-color: #6c757d;
  color: white;
}

.back:hover {
  background-color: #5a6268;
}
</style>
